package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 图片上传
     */
    @PostMapping("/upload_picture")
    //参数是前端传过来的，就是multipartFile,如果想用file,请写成public ResponseResult upload(@RequestParam("multipartFile") MultipartFile file){return null;}
    public ResponseResult upload(@RequestParam("multipartFile") MultipartFile file){
        return wmMaterialService.upload(file);
    }

    /**
     * 图片列表查询
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto){
        return wmMaterialService.list(dto);
    }

    /**
     * 收藏
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult isCollection(@PathVariable Integer id){
        return wmMaterialService.isCollection(id);
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollection(@PathVariable Integer id){
        return wmMaterialService.isCollection(id);
    }

    /**
     * 删除素材
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult deletePicture(@PathVariable Integer id){
        return wmMaterialService.deletePicture(id);
    }
}
